<?php
function reequipment_user_main()
{
	if (!xarVarFetch('company_id', 'int:1:', $company_id, '', XARVAR_NOT_REQUIRED)) return;
	if (!xarModAPIFunc('reequipment', 'user', 'getcompanyid', array('company_id_from_url' => $company_id))) return;
	$company_id = xarSessionGetVar('company_id');
	if (!xarSecurityCheck('EditEquipment', 1)) return;
    $data = array();
	xarTplSetPageTitle(xarML('Dashboard'));
	// return $company_id;

	// Company Name
	$companies = xarModAPIFunc('reequipment', 'user', 'getrel', array('company_id' => $company_id));
	foreach($companies as $var){
		$data['company_name'] = $var['company_name'];
	}

    // Data
    $data['models'] = xarModAPIFunc('reequipment', 'user', 'getmodels');
    $data['items'] = xarModAPIFunc('reequipment', 'user', 'getitems', array('company_id' => $company_id, 'inventory' => true));
	$data['pending'] = xarModAPIFunc('reequipment', 'user', 'getorders', array('company_id' => $company_id, 'equipment_id' => 0, 'is_open' => true));
   	$data['equipment'] = xarModAPIFunc('reequipment', 'user', 'getequipment', array('company_id' => $company_id));
   	$data['maintenance']  = xarModAPIFunc('reequipment', 'user', 'getmaintenance', array('date_complete' => true, 'company_id' => $company_id, 'unscheduled' => true));
    $data['overdue'] = xarModAPIFunc('reequipment', 'user', 'getmaintenance', array('over_due' => true, 'date_complete' => true, 'company_id' => $company_id));
    $data['overdue_parts'] = xarModAPIFunc('reequipment', 'user', 'getorders', array('over_due' => true, 'company_id' => $company_id, 'is_open' => true));
	foreach ($data['overdue_parts'] as $key => $var){
		$data['overdue_parts'][$key]['description'] = substr($var['description'], 0, 60);
	}
    // return var_export($data['overdue_parts']);

    return $data;
}

?>